package com.example.online_order.conrtoller;

import com.example.online_order.pojo.AdminAccount;
import com.example.online_order.pojo.Desk;
import com.example.online_order.pojo.Result;
import com.example.online_order.service.AdminAcountService;
import com.example.online_order.service.DeskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/desk")
@CrossOrigin
@Slf4j
public class DeskController {
    @Autowired
    DeskService deskService;
    @GetMapping("/getAllDesks")
    public Result getAllDesks(){
        return new Result(deskService.getAllDesks());
    }

    @GetMapping("/getDeskById/{id}")
    public Result getDeskById(@PathVariable("id") Integer id){
        return new Result(deskService.getDeskById(id));
    }

    @PostMapping("/addDesk")
    public Result addDesk(@RequestBody Desk desk){
        Integer res = deskService.addDesk(desk);
        if (res != null ){
            return new Result(desk);
        }else{
            return  Result.fail("Desk already",500);
        }
    }

    @DeleteMapping("/delDesk/{id}")
    public Result delAdmin(@PathVariable("id") Integer id){
        Integer res = deskService.deleteDesk(id);
        if (res == 1){
            return new Result("delete success");
        }else{
            return  Result.fail("delete failed",444);
        }
    }
//    查询，新增，删除
}
